import { reqCartList } from "../api";
const state = {
    cartList: [],
};
const mutations = {
    GETCARTLIST(state, cartList) {
        state.cartList = cartList;
    }
};
const actions = {
    //获取购物车列表数据
    async getCartList({ commit }, sid) {
        let result = await reqCartList();
        if (result.code == 200) {
            commit("GETCARTLIST", result.data);
        }
    },
    async addCartList({ commit }, { sid, skuNum }) {
        //加入购物车返回的结果
        let result = await reqCartList(sid, skuNum);
        //代表服务器加入购物车成功
        if (result.code == 200) {
            return "ok"
        } else {
            //代表加入购物车失败
            return Promise.reject(new Error('faile'));
        }
    },
};



const getters = {
    cartList(state) {
        return state.cartList[0] || []
    },
    //计算出来购物车
};
export default {
    state,
    mutations,
    actions,
    getters
}

// import { reqCartList } from "../api";
// const state = {};
// const mutations = {};
// const actions = {
//     //获取购物车列表数据
//     getCartList({ commit }) {
//         let result = reqCartList();
//     }
// };
// const getters = {};
// export default {
//     state,
//     mutations,
//     actions,
//     getters
// }
